added averageLayout function