Fix dirty flag not clearing