small code rewrite