refactoring because click event is not working