David, can you explain what this extra if block is used for? It would be good to add some comments to the file to distinguish between the two cases as it's difficult to figure this out from reading the code