Finished findMode

and associated sub-functions