adding support for MetaStateEvent
refactoring and commenting