refactor out threshold