Fixes some bugs with add_key

I actually tested it this time :)