Rewrite brought to working level