new functions.js and fixed some js errors