Fixed c# implementation and some minor bugs in ruby impl.