Refactored and in JavaScript