Add ASCII-check

This increases the size, but it's worth it for extra security
Small size improvement
Fixed performance issue with large inputs
Some refactoring