remove some duplication in handlEvent.