Initial API implementation. Not fully tested.