tries to write past heap, don't know what to fix