refactor bitmatrix gen