Add cpo guard
Simplify check condition
Use fugitive function if exists.
Improve global variables initialization.