ruby to c# port added, f# version optimized