First attempt at making main loop a recursive function
Refactored solution to not use mutables