Refactor and add more tests for the layout and navigation