Prep. for event emmission

introduced EventQuery to support more complex queries
introduced event notification listener
some refactoring and under-the-hood improvements