diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 79703cf104a6bdf2bd0ef92248964273609f241a..67384cf5bea95615cf22b93f445dd8b20f7cb678 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -8,18 +8,18 @@ class CommitsController < ApplicationController
   before_filter :add_project_abilities
   before_filter :authorize_read_project!
   before_filter :require_non_empty_project
+  before_filter :load_refs, :only => :index # load @branch, @tag & @ref
 
-  def index
-    load_refs # load @branch, @tag & @ref
 
+  def index
     @repo = project.repo
     limit, offset = (params[:limit] || 20), (params[:offset] || 0) 
 
-    if params[:path]
-      @commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset)
-    else
-      @commits = @repo.commits(@ref, limit, offset)
-    end
+    @commits = if params[:path]
+                 @repo.log(@ref, params[:path], :max_count => limit, :skip => offset)
+               else
+                 @repo.commits(@ref, limit, offset)
+               end
 
     respond_to do |format|
       format.html # index.html.erb
@@ -29,8 +29,8 @@ def index
 
   def show
     @commit = project.repo.commits(params[:id]).first
-    @notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit").order("created_at DESC").limit(20)
-    @note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit")
+    @notes = project.commit_notes(@commit).fresh.limit(20)
+    @note = @project.build_commit_note(@commit)
 
     respond_to do |format| 
       format.html
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 5e00fe461e6f9f59e63438952a88955b6abaa9d4..0494e1820def73c8489158c60e43c5b702d999d3 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -6,8 +6,8 @@ class ProjectsController < ApplicationController
   before_filter :add_project_abilities
   before_filter :authorize_read_project!, :except => [:index, :new, :create]
   before_filter :authorize_admin_project!, :only => [:edit, :update, :destroy]
-
   before_filter :require_non_empty_project, :only => [:blob, :tree]
+  before_filter :load_refs, :only => :tree # load @branch, @tag & @ref
 
   def index
     source = current_user.projects
@@ -101,15 +101,13 @@ def wall
   #
 
   def tree
-    load_refs # load @branch, @tag & @ref
-
     @repo = project.repo
 
-    if params[:commit_id]
-      @commit = @repo.commits(params[:commit_id]).first
-    else
-      @commit = @repo.commits(@ref).first
-    end
+    @commit = if params[:commit_id]
+                @repo.commits(params[:commit_id]).first
+              else
+                @repo.commits(@ref).first
+              end
 
     @tree = @commit.tree
     @tree = @tree / params[:path] if params[:path]
diff --git a/app/models/project.rb b/app/models/project.rb
index 9767352f1eeaa34149883412045315657b322882..e4448e786e98a72b9303b2f9b9364adace418b27 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -51,6 +51,10 @@ def repository
   end
 
   delegate :repo,
+    :url_to_repo,
+    :path_to_repo,
+    :update_gitosis_project,
+    :destroy_gitosis_project,
     :tags,
     :repo_exists?,
     :commit,
@@ -74,16 +78,12 @@ def common_notes
     notes.where(:noteable_type => ["", nil])
   end
 
-  def update_gitosis_project
-    Gitosis.new.configure do |c|
-      c.update_project(path, gitosis_writers)
-    end
+  def build_commit_note(commit)
+    notes.new(:noteable_id => commit.id, :noteable_type => "Commit")
   end
 
-  def destroy_gitosis_project
-    Gitosis.new.configure do |c|
-      c.destroy_project(self)
-    end
+  def commit_notes(commit)
+    notes.where(:noteable_id => commit.id, :noteable_type => "Commit")
   end
 
   def add_access(user, *access)
@@ -121,14 +121,6 @@ def private?
     private_flag
   end
 
-  def url_to_repo
-    "#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git"
-  end
-
-  def path_to_repo
-    GITOSIS["base_path"] + path + ".git"
-  end
-
   def last_activity 
     updates(1).first
   rescue 
diff --git a/app/models/repository.rb b/app/models/repository.rb
index da679d8bb9e39b88686cd053170d7148c4051c38..c01320e81d0e5ac60e0f318b85cb7d8366035b1d 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -9,24 +9,48 @@ def initialize(project)
     @project = project
   end
 
+  def path 
+    @path ||= project.path
+  end
+
+  def project_id
+    project.id
+  end
+
   def repo
     @repo ||= Grit::Repo.new(project.path_to_repo)
   end
 
-  def tags
-    repo.tags.map(&:name).sort.reverse
+  def url_to_repo
+    "#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git"
+  end
+
+  def path_to_repo
+    GITOSIS["base_path"] + path + ".git"
+  end
+
+  def update_gitosis_project
+    Gitosis.new.configure do |c|
+      c.update_project(path, project.gitosis_writers)
+    end
+  end
+
+  def destroy_gitosis_project
+    Gitosis.new.configure do |c|
+      c.destroy_project(@project)
+    end
   end
 
   def repo_exists?
     repo rescue false
   end
 
-  def commit(commit_id = nil)
-    if commit_id
-      repo.commits(commit_id).first
-    else
-      repo.commits.first
-    end
+  def tags
+    repo.tags.map(&:name).sort.reverse
+  end
+
+  def heads
+    @heads ||= repo.heads
   end
 
   def tree(fcommit, path = nil)
@@ -35,6 +59,14 @@ def tree(fcommit, path = nil)
     path ? (tree / path) : tree
   end
 
+  def commit(commit_id = nil)
+    if commit_id
+      repo.commits(commit_id).first
+    else
+      repo.commits.first
+    end
+  end
+
   def fresh_commits(n = 10)
     commits = heads.map do |h|
       repo.commits(h.name, n)
@@ -47,10 +79,6 @@ def fresh_commits(n = 10)
     commits[0...n]
   end
 
-  def heads
-    @heads ||= repo.heads
-  end
-
   def commits_since(date)
     commits = heads.map do |h|
       repo.log(h.name, nil, :since => date)