Added debug cmd for event checking. Code cleanup