re worked conditional to use function