refactor to use stream api in some methods.