Refactored click handlers to use common function.