Move the packages and keys into their own packages

Not the easiest thing to review, since some of the moved files needed some changes to make this work.

Improve #282.
Resolve #291.