Cleaned up implementation of the SAT algorithm.