memory optimization

using pointer to pointer instead of sentinel head