From the method name I can guess what the method intent is, but this logic isn't the most clear thing to follow. Could the behavior here be changed to be more readable or barring that could we get documentation explaining what's going on here?