smart text by @raxoft

See #336. This is the cleaned up version.