fix for malloc memory corruption error

Issue #36