reworked span logic