Massive bug fixes - including error catching