refactored js into an object