Refactor minor parts, add new diagnostic event