altered tie mechanism to use a double-nested for loop