beging attempt at smart threshold