Use lambdas instead of nested for-loops