Fix error checking