Adapted to the storage model. Need some cleanup and unit tests.