more callbacks and refactoring