fixed path calculation bug and added tests