This is a pretty nasty bug right there. I'm going to see if I can reproduce it and find the source, otherwise I'll add a safeguard double checking what keys has been picked up and what doors have been opened, and basing the key counter on that.
Thanks for the report!