WIP: factorize now works. more code needs to be modified.