Implemented events correctly.
Modified and moved code related to events.