rewrite to use db storage for metadata; put stuff under model; add test.
rewrite to use db storage for metadata; put stuff under model; add test. pt2