working version before switching to assigning event handlers through .on()