Initial implementation. Better test coverage still needed.