add tests, start to modularize