Got recursive algorithm working for quantiation mods