un-DRY version of sorting blocks