passing $type through loop()