Thanks for the lesson @CJK. I think there is a small error in getting the result's count by doing:
if (count T) = 0 then return null
-- Logging (count T) always returns (*2*)
-- Logging T returns (*,*) when no empty tabs are open.
Thus, throwing an error by accessing item 1 of item 1 when no empty tab is open.
It works with:
if (count item 1 of T) = 0 then return null