Refactoring and uri escape fix