Refactor (to reduce number of lines of JS in this repo).