larger refactoring to enable more advanced compilation