added canvas state save and restore