Update logic.py

Added better support for non-ASCII characters.