reorganize code, add tests for basic metadata