It would be nice to move this code to its function and add a test case for it