finish core algorithm