Fix memory corruption as of issue #2