refactor, separate conerns in JS