Implemented more of #11. Tests are TODO.