Debugged. changed scope of b and k variables.