Refactoring JavaScript API, not tested yet