extend to n dim and n class