fix threshold logic