Refactor callback handling