Refactor of custom.js