Add some if logic to prevent barfing on empty strings in a loop