Rewrite some parts of the code