added weak references; de-inlined most functions
simplified the weakref interface