revised auto focus function