refine code a little