Fixed the way URLs were generated and refactored a lot of code