Refactor of javascript and API implementation