Improve overwriting logic