Refine the code according to Sean B's comments.