fixing addition to the head and removal from tail special cases