refactored CodeAnalysis to isolate duplicate error checking code