changed l/r threshold code