Restructuring. Adopted Symfonys rewrite logic for more flexibility