Restructured to separate .js files, made functions more ObjectOrientified