only clearRect when necessary