used .length() method of string, instead of calling strlen