Restructuring url-handling code into multiple functions (separating out SQL call handling)