Refactor: cleaning code with lambda