finished the Buhlann function (working version, tested)