Tidied up SAT code