Commiting changes before modifying recursive method