Refactoring the internals, but respecting the current API

Setting up for massive rearch of internals.