Duplicate events

Added code to check whether an event exists or not to prevent duplicate
entries.
Encapsulated code for duplicate events.

Code that checks for duplicate events is now encapsulated into its own
method.