Fixed a bug in events handling.