buggy implementation of BCD algorithm (cont'd)