Change sum_modulo from layer to free functions