improved isDirty method