Fix some bugs in smart_pointer and add unit tests