reformatted code and improved data-flow. Also added comments. Added legacy folder for unused but maybe usable files. Moved hsi.js and plotcanvas.js to legacy.