memory leak and weakref fixes - fixes #56