Commented top half of jsfile
refactor and add comments