refactoring of stave js