You'd better check string variable before use its index in every function