Improve dependency structure, add test
Change to use stream API