Move logic out of button clicks