refactor definition of on method