Preventing downcasting when the object can be null, fixing the incorrect display of line item count and other refactoring

preventing direct down casting with out checking for null as some of the member fields of the Event can be null. Refactoring is done to make the code precise rather than using intermediate variables instead of directly assigning the value and use of generic Object type unnecessarily.