Some cleanup and move some defs to an internal header