Added some exceptions and other minimal modifications.