Refine code and comments