adding some error checking to unit and more comments