Found the issue. The fact that I was not removing keys from the selected key set after processing was the problem.