moved life inner loop to C# for performance