refactored for browser usage