Move 'on' to a separate function