added prev pointer to insertMiddle()