refactor to two stage checks and compiles