Move events outside of function and use jQuery proxy