Very buggy factorization... need to refactor (lol)