add some fool-proof dealloc code, allow decreasing capacity