Duplicate code

Moved this to api.js earlier.