Added custom events/callbacks. Split project into library and run script to demonstrate and test the event API.