Separated the processing to a different function with a return statement, so that the functionality can be tested.