Clean up and document api.js