Fixed bugs in clearing canvas