Refactoring js, somethings left undone