Cleaned up new api.py code