Fix warning about onX functions not being declared
Move template into its own function, just for fun
Clean-up