cleaned up internals, added hooks