simplifying code + dynamic threshold