Some fixes and cleanups
Use ranges for type ids to check against hierarchy types faster.
Some optimizations to make the compiler faster by avoiding memory allocations when possible