fix bug when T is empty
Record is not always the key to solve problem. Breadth first searh, and implement it effectively.