Clean Code based on jlee-r7's comments

- Put allocations in loop

- Decomment exitfunc

- Aligned comments

- Some more code cleaning