Major refactor to get rid of the shared_ptr mess and change to
streamlined system with unique ownership and naked pointers. Untested as
yet.
Merge branch master from origin