reordered and cleanup on functions.js