Finished version 2 with functions, check atm2.js