starting the refactor of code
almost there
almost tested
refactor of js done!