improvement on click function