Refactoring: Simplified encodeUrl method