Bug Fix

Fix bugs introduced in the conversion from c#