Improved reference-counted pointer

Added some unit tests about the reference-counted pointer and simplified complicated type definitions.