Fixed a few logical errors.