fixed various dynamic allocation bugs