Allow other API URLs
Some minor code cleanups. Currently untested.