Fixed a bug with pencil tool