Merge Logan's changes to api.py

This superceeds pull request #82.