First phase of refactoring of functions.js