Bug Fix

Fix bugs introduced in the conversion from c#
Merge pull request #1 from Tornchi/master

Bug Fixes