Improved string parsing