Move these events inside the if statement.