I find this logic difficult to follow, can you explain what this code is doing?