Refactoring and update to new libgit version