Reimplement loop without side-effects