Fixes to heap access error