Refactor event handlers into extension.
Merge pull request #628 from kadams54/added-services-db-refactor

Refactor event handlers into extension.

Also wrap tests around the event handlers.