Refactor: refactor the finalString method