moved main.js contents to api.js