adding events to ids and cleaned up some code