check for string truthiness before accessing characters