Refactored JS structure