refactoring to be able to run in browser