refactoring code and applying events to home page