refactor doCompile function