added more error info to messages
Moved event code to bottom of file.