refactor and add some test for the page