Fix memory corruptions.
Merge pull request #18 from crimsonwoods/fix_memory_corruption

Fix memory corruptions.