Lots of additions from porting from C#