you can initialize `$next = $prev = null;` before this block