Added event handling. Some small changes in other files.