Moved all functions into, well, functions.
Added --performUpgrade (currently untested).
Removed an unused function (processJSON()).