Debug fixes involving some ref counting
Conflicts resolved