Added two small error checks to prevent accessing attributes of objects that do not exist.