Add formula handling and CNF encoding