fix various footpath bugs and refactor, fixes #637