Refine the code according to Ram's comments.