Code cleanup + primitives