Added functionality to check the end conditions and display the results.