Initial port from C# sources.

Just testing.