refactoring code using Lambda Expression in Java 8