rewriting c# to java. Still needs more work, but getting there