refine code for bug #239