implement bg function, test it in primery version test and fix warnings