preliminary decomposition code
working implementation