[BUGFIX] Fix various code errors and CGL violations