Added EVENT handling and cleaned trailing whitespace