fixed events handling (seems to work)