Added dirty state checking