Refactoring for proper url encoding