refactor; clean up code to handle click listeners