refine code and veiw