Optimization code, added two events