whitelisting printable characters, further refactoring