Clean up api.py

Get rid of redundant code.