refactor the toString() function