Restructure code and tests. Remove dead code.