Reformat the code and change the order of check cases