correctly handles white space at end of string