Refactoring loop, to reduce filesize footprint