refactor click button function