bug fix and added testsssss from OPT repo