Support nested $refs

Fixed  #166