Code refactoring

All the functions are now in js/functions.js