added all current changes with incomplete implementation of the algorithm