code for defensive programming with strings