Bug fixes and testing

Fixed some bugs in the code and expanded and corrected some error
catching constructs.