fix allocation order bug