multiple instances and group by head function