Update logic.py

Better support for non-ASCII characters.