Added the Create Event functionality and cleaned the code