routing refactor and bug fixes