Improved string checking