It seems you accidentally left in some of the auto generated code in your source, so contentHandler is always being called immediately. It should work if you remove the first block of code calling it
if let bestAttemptContent {
contentHandler(bestAttemptContent) // REMOVE this if statement
}