changed optimization criterion to boundary detection