tile: optimize and clean up string functions