Removed weird threading code.
Improved event handling and exceptions.
Rewritten most of the code.