fixes bug with head
also fixes tail