Updated main to handle spawn command.
Improved the event mapping function.