Add loop helper and clean code