implement callbacks, refactor test