Collecting results and rearranging code