Fixed an error while adding reference counts.
Still need to test thoroughly the whole commit process.