some refactoring, fixed some logical bugs, added support to listen on certain events that will trigger an update of the current state, added support for a callback that is triggered after the update