attempt to fix #566 and other bugs, also refactor some footpath related functions