better error checking