made some error checking a bit nicer