Complete implementation, some tests.