Fairly complete implementation with test