refactored js with lorin