Initial (mostly untested) implementation.