Working version of sat solver