almost finished functional.js