WIP

Some refactors to use more native JS functions