support for callbacks, cleaned up code