refactor some common callback code into a separate class