reordering the error detection