Fix import, doctests, and function parameters in keys.py