Cleanup, move all API stuff to api.py file.