Replaced hardcoded threshold with variable