Second phase of refactoring of functions.js