reorganize and add some integration tests