Added event infrastructure tests. Some cleanup and bug fixing