Implemented addPath function and refactored code