added two functions to automatically define discretization threshold. but not used anywhere yet.