add a builder class
simplify builder and add tests for it