cleaned up the code in functions.js