Implemented events and fixed various stuff