Reverted to simpler logic function now that tests pass in both ways