More principled use of setkeys.
Closes #193. Closes #255