Fixes fatal JSON.parse bug. Refactors main.js to remove repetition. Introduces errors.js
Merge remote-tracking branch 'upstream/master'