Minor refactoring

Just moving functions around for reusability, and added uri encoding