Fix bugs in client-side routing and refactor.