some code rewrite