button click function refactor