Change to dynamic allocate buffer