Events api optimization and bugfix