Improve factorize, add more tests.