Some code rewritten