Fixes to overwriting bug