reorganize code; add primitive tests