code rewritten