Added proper termination conditions so we don't have to iterate through the list to check if it's sorted