added Giannis' and fixed get family and total cost query