Merge Logan's changes to api.py

This superseeds pull request #82.