Refactor clientside javascript, utils