Corrected mistake, added missing conditions.