Cleaned up MD code

Now has simple event handling system