terniry check added to prevent nulls, the need for a final variable makes this extra HashSet ksToRecover variabe necessary