Refactor/tree transform inits

Replaces imperative init method by prepareForUnit/transformUnit. Makes phases better parallelizable. Review by @DarkDimius