fix medium memory crash and save prime