restructure code and tests