completed refactoring, added events for clicks