added mode based threshold selection