Big overhaul -- implement error handling