Refs #3946: improve logic and comment to make the code more understandable