Initial basic functionality. Lots to do: refactor (because urgh), add raw handler, etc.