Mended bugs pertaining to reference counts