Simplify loop function inside Main