minor refactoring for more JS-like api