Rewriting some code