refactor escape string method