improved supercell function