JS refactored