modified bs.functions.new.r file