Generate a base URL once outside of the results loop since instead of on each iteration. Also, a lot of other cleanup.