core function for butterflies