Use local variables in order to leave the environment untouched

Another issue found... after bd is used, its variables are left in the current environment, that's definitely unwanted and may cause side effects. Instead, let's use local variables.