refactoring to add js implementation