restructured .js file and almost working directions function from pt to pt