fixed some error checking business