Moved event bindings into their own functions