adding some error checking