fixed checks to allow head=-1 and tail not