added apis.js, code cleanup