increase performance
events processing into separate function