removed un-necessary casting of objects and wrote more simpler code