Refactor compilation to  use callbacks throughout.