optimizing kaaEMonitor code