JS Refactor for fun

should be a bit easier to read now?