simplify loops and decouple them