Rebase PR #99 and fix up

Rebase gsalgado's changes from #99, adding tests.

Also, change the semantics of 'Key.rename' to return the new key without mutating the original.