refactored in js