Fix some error checking