Implemented StringBuilder in getPath method to improve performance