Fix dirty flag setting