Compilability + weak reference unittests

Fixed minor issues preventing compilation, including a segfault in the
strong reference constructor algorithm. Added unittest for weak
reference semantics.