refactoring plus test environment for js