Fixed lambda capturing by reference when it should have been capturing by value