Fixed infinite loop when dealing with subs