Code clean up in functions.js