Attempted to fix some logic errors. They still exist.