Code cleanup for button events