fix for malloc memory corruption error (issue #36)