improved dirty rect implementation