Cleanup.
Added uniform reference counting. Reorg some header/source implementation.