Merge my current work done on the kd++ branch: