I reordered the code in a more clean an organized way. Also this improves a lot the emacs startup time again, bucause after some updates it becomes a bit slow with the old configuration, so i did it again in a new way.
In another oportunity i will optimize this again.
The build-in version do not fit with magit requeriment.