Improve how the search page behaves and do some refactoring