Fixed issue with heap corruption