code and test rewrite