Fixes bug in overwrite code