Refactor tests and encapsulation
Change callbacks to use error-passing convention