diff --git versioncontrol_git.log.inc versioncontrol_git.log.inc
index 0079cc9..c330823 100644
--- versioncontrol_git.log.inc
+++ versioncontrol_git.log.inc
@@ -23,25 +23,26 @@
 function _versioncontrol_git_log_update_repository(&$repository) {
   $root = escapeshellcmd($repository->root);
   putenv("GIT_DIR=$root/.git");
+
   if ($repository->locked == TRUE) {
     drupal_set_message(t('This repository is locked, there is already a fetch in progress. If this is not the case, press the clear lock button.'), 'error');
     return FALSE;
   }
-  // $repository->locked = 1;
-  // $repository->update();
+  $repository->locked = 1;
+  $repository->update();
 
   // Fetch branches from the repo and load them from the db.
   $branches_in_repo = $repository->fetchBranches();
-  $bdb = $repository->loadBranches();
-  $branches_in_db = array();
-  foreach ($bdb as $branch) { // Branches get keyed on id; key on name instead.
-    $branches_in_db[$branch->name] = $branch;
+  $branches_in_db = $repository->loadBranches();
+  $branches_in_db_by_name = array();
+  foreach ($branches_in_db as $branch) { // Branches get keyed on id; key on name instead.
+    $branches_in_db_by_name[$branch->name] = $branch;
   }
-  unset($bdb);
+  unset($branches_in_db);
 
   // Determine whether we've got branch changes to make.
-  $branches_new = array_diff_key($branches_in_repo, $branches_in_db);
-  $branches_deleted = array_diff_key($branches_in_db, $branches_in_repo);
+  $branches_new = array_diff_key($branches_in_repo, $branches_in_db_by_name);
+  $branches_deleted = array_diff_key($branches_in_db_by_name, $branches_in_repo);
 
   // Insert new branches in the repository. Later all commits in these new
   // branches will be updated.
@@ -50,56 +51,56 @@ function _versioncontrol_git_log_update_repository(&$repository) {
   // We also can't insert a VCOperation which adds the branch, because
   // we don't know anything about the branch. This is all stuff a hook could
   // figure out.
-  // Here we will just ensure that each branch is in the database.
   foreach($branches_new as $branch) {
-    $branch->ensure();
+    $branch->insert();
   }
   // reload branches, after they was inserted
-  $branches_in_db = $repository->loadBranches();
+  $branches_in_db_by_name = $repository->loadBranches();
   $branches_label_list = array();
-  foreach ($branches_in_db as $branch) {
+  foreach ($branches_in_db_by_name as $branch) {
     $branches_label_list[$branch->name] = $branch;
   }
 
   // Deleted branches are removed, commits in them are not!
-  // FIXME could deleting the branch first cause inconsistencies?
   foreach($branches_deleted as $branch) {
     $branch->delete();
   }
 
-  $cdb = $repository->loadCommits();
-  $commits_in_db = array();
-  foreach ($cdb as $commit) {
-    $commits_in_db[] = $commit->revision;
+  // Fetch commits from the repo and load them from the db.
+  $commits_in_repo_hashes = $repository->fetchCommits();
+  $commits_in_db = $repository->loadCommits();
+  $commits_in_db_hashes = array();
+  foreach ($commits_in_db as $commit) {
+    $commits_in_db_hashes[] = $commit->revision;
   }
-  unset($cdb);
-  $commits_in_repo = $repository->fetchCommits();
-  $commits_new = array_diff($commits_in_repo, $commits_in_db);
+  unset($commits_in_db);
+  $commits_new = array_diff($commits_in_repo_hashes, $commits_in_db_hashes);
 
   // Insert new commits in the database.
-  foreach ($commits_new as $sha1) {
-    $command = "git show --numstat --summary --pretty=format:\"%H%n%P%n%aN <%ae>%n%cN <%ce>%n%ct%n%s%n%b%nENDOFOUTPUTGITMESSAGEHERE\" " . escapeshellarg($sha1);
+  foreach ($commits_new as $hash) {
+    $command = "git show --numstat --summary --pretty=format:\"%H%n%P%n%aN <%ae>%n%cN <%ce>%n%ct%n%s%n%b%nENDOFOUTPUTGITMESSAGEHERE\" " . escapeshellarg($hash);
     $output = _versioncontrol_git_log_exec($command);
-    _versioncontrol_git_log_parse_and_insert_commit($repository, $output, $commits_in_db, $branches_label_list);
+    _versioncontrol_git_log_parse_and_insert_commit($repository, $output, $branches_label_list);
   }
 
   // Add a new branch to all commits contained in that branch.
   foreach ($branches_new as $branch_new) {
     $commits_ids = _versioncontrol_git_log_get_commits_in_branch($branch_new);
     $commits = $repository->loadCommits(array(), array('revision' => $commit_ids));
-    _versioncontrol_git_log_attach_branch_to_commits($branches_in_db[$branch_new], $commits);
+    _versioncontrol_git_log_attach_branch_to_commits($branches_in_db_by_name[$branch_new], $commits);
   }
 
   // Insert new tags in the database.
   $tags_in_repo = $repository->fetchTags();
-  $tdb = $repository->loadTags();
-  $tags_in_db = array();
-  foreach ($tdb as $tag) {
-    $tags_in_db[$tag->name] = $tag;
+  $tags_in_db = $repository->loadTags();
+  $tags_in_db_by_name = array();
+  foreach ($tags_in_db as $tag) {
+    $tags_in_db_by_name[$tag->name] = $tag;
   }
+  unset($tags_in_db);
   // Deleting tags is *not* supported. Read the manual if you want to know why...
   // Check for new tags.
-  $tags_new = array_diff_key($tags_in_repo, $tags_in_db);
+  $tags_new = array_diff_key($tags_in_repo, $tags_in_db_by_name);
   if (!empty($tags_new)) {
     _versioncontrol_git_log_process_tags($repository, $tags_new);
   }
@@ -281,10 +282,9 @@ function _versioncontrol_git_parse_items(&$logs, &$line, $data, $parents) {
  *
  * @param VersioncontrolRepository $repository
  * @param array $logs The output of 'git log' to parse
- * @param array $commits_in_db
  * @param array $branch_label_list An associative list of branchname => VersioncontrolBranch
  */
-function _versioncontrol_git_log_parse_and_insert_commit($repository, $logs, &$commits_in_db, $branch_label_list) {
+function _versioncontrol_git_log_parse_and_insert_commit($repository, $logs, $branch_label_list) {
   // Get Revision
   $revision = trim(next($logs));
 
@@ -348,8 +348,6 @@ function _versioncontrol_git_log_parse_and_insert_commit($repository, $logs, &$c
   $op->build($data);
   $op->labels = _versioncontrol_git_log_get_branches_of_commit($revision, $branch_label_list);
   $op->insert($op_items);
-
-  $commits_in_db[] = $op;
 }
 
 /// All branch related functions
