Refactoring JS and removing the generateURL nonsense