diff --git a/lib/tasks/migrate_from_mantis.rake b/lib/tasks/migrate_from_mantis.rake
index e74b879..4e3960e 100644
--- a/lib/tasks/migrate_from_mantis.rake
+++ b/lib/tasks/migrate_from_mantis.rake
@@ -20,7 +20,7 @@ desc 'Mantis migration script'
 require 'active_record'
 require 'iconv'
 require 'pp'
-
+ActiveRecord::Base.record_timestamps = false
 namespace :redmine do
 task :migrate_from_mantis => :environment do
   
@@ -41,13 +41,13 @@ task :migrate_from_mantis => :environment do
                         }
                         
       priorities = IssuePriority.all
-      DEFAULT_PRIORITY = priorities[2]
-      PRIORITY_MAPPING = {10 => priorities[1], # none
-                          20 => priorities[1], # low
-                          30 => priorities[2], # normal
-                          40 => priorities[3], # high
-                          50 => priorities[4], # urgent
-                          60 => priorities[5]  # immediate
+      DEFAULT_PRIORITY = priorities[1]
+      PRIORITY_MAPPING = {10 => priorities[0], # none
+                          20 => priorities[0], # low
+                          30 => priorities[1], # normal
+                          40 => priorities[2], # high
+                          50 => priorities[3], # urgent
+                          60 => priorities[4]  # immediate
                           }
     
       TRACKER_BUG = Tracker.find_by_position(1)
@@ -82,7 +82,7 @@ task :migrate_from_mantis => :environment do
                                0 => IssueRelation::TYPE_DUPLICATES, # duplicate of
                                4 => IssueRelation::TYPE_DUPLICATES  # has duplicate
                                }
-                                                                   
+        
     class MantisUser < ActiveRecord::Base
       set_table_name :mantis_user_table
       
@@ -119,10 +119,14 @@ task :migrate_from_mantis => :environment do
       has_many :members, :class_name => "MantisProjectUser", :foreign_key => :project_id
       
       def identifier
-        read_attribute(:name).gsub(/[^a-z0-9\-]+/, '-').slice(0, Project::IDENTIFIER_MAX_LENGTH)
+        read_attribute(:name).slice(0, Project::IDENTIFIER_MAX_LENGTH).downcase.gsub(/[^a-z0-9\-]+/, '-')
       end
     end
     
+    class MantisProjectHierarchy < ActiveRecord::Base
+        set_table_name :mantis_project_hierarchy_table
+    end
+    
     class MantisVersion < ActiveRecord::Base
       set_table_name :mantis_project_version_table
       
@@ -136,7 +140,10 @@ task :migrate_from_mantis => :environment do
     end
     
     class MantisCategory < ActiveRecord::Base
-      set_table_name :mantis_project_category_table
+      set_table_name :mantis_category_table
+      def category
+        read_attribute(:name).slice(0,30)
+      end
     end
     
     class MantisProjectUser < ActiveRecord::Base
@@ -149,6 +156,7 @@ task :migrate_from_mantis => :environment do
       has_many :bug_notes, :class_name => "MantisBugNote", :foreign_key => :bug_id
       has_many :bug_files, :class_name => "MantisBugFile", :foreign_key => :bug_id
       has_many :bug_monitors, :class_name => "MantisBugMonitor", :foreign_key => :bug_id
+      belongs_to :category, :class_name => "MantisCategory", :foreign_key => :category_id
     end
     
     class MantisBugText < ActiveRecord::Base
@@ -243,18 +251,18 @@ task :migrate_from_mantis => :environment do
       users_map = {}
       users_migrated = 0
       MantisUser.find(:all).each do |user|
-    	u = User.new :firstname => encode(user.firstname), 
-    				 :lastname => encode(user.lastname),
-    				 :mail => user.email,
-    				 :last_login_on => user.last_visit
-    	u.login = user.username
-    	u.password = 'mantis'
-    	u.status = User::STATUS_LOCKED if user.enabled != 1
-    	u.admin = true if user.access_level == 90
-    	next unless u.save!
-    	users_migrated += 1
-    	users_map[user.id] = u.id
-    	print '.'
+        u = User.new :firstname => encode(user.firstname), 
+             :lastname => encode(user.lastname),
+             :mail => user.email,
+             :last_login_on => user.last_visit
+       u.login = user.username
+       u.password = 'mantis'
+       u.status = User::STATUS_LOCKED if user.enabled != 1
+       u.admin = true if user.access_level == 90
+       next unless u.save!
+       users_migrated += 1
+       users_map[user.id] = u.id
+       print '.'
       end
       puts
     
@@ -265,42 +273,51 @@ task :migrate_from_mantis => :environment do
       versions_map = {}
       categories_map = {}
       MantisProject.find(:all).each do |project|
-    	p = Project.new :name => encode(project.name), 
-                        :description => encode(project.description)
-    	p.identifier = project.identifier
-    	next unless p.save
-    	projects_map[project.id] = p.id
-    	p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
-        p.trackers << TRACKER_BUG
-        p.trackers << TRACKER_FEATURE
-    	print '.'
-    	
-    	# Project members
-    	project.members.each do |member|
+        p = Project.new :name => encode(project.name), 
+                        :description => encode(project.description),
+                        :trackers => [TRACKER_BUG,TRACKER_FEATURE]
+        p.identifier = project.identifier
+        p.is_public = (project.view_state == 10)
+        next unless p.save
+        projects_map[project.id] = p.id
+        p.enabled_module_names = ['issue_tracking', 'news', 'wiki']
+        print '.'
+
+        # Project members
+        project.members.each do |member|
           m = Member.new :user => User.find_by_id(users_map[member.user_id]),
-    	                   :roles => [ROLE_MAPPING[member.access_level] || DEFAULT_ROLE]
-    	  m.project = p
-    	  m.save
-    	end	
-    	
-    	# Project versions
-    	project.versions.each do |version|
+                         :roles => [ROLE_MAPPING[member.access_level] || DEFAULT_ROLE]
+          m.project = p
+          m.save
+        end	
+
+       # Project versions
+        project.versions.each do |version|
           v = Version.new :name => encode(version.version),
                           :description => encode(version.description),
-                          :effective_date => (version.date_order ? version.date_order.to_date : nil)
+                          :effective_date => (version.date_order ? Time.at(version.date_order).to_date : nil)
           v.project = p
           v.save
           versions_map[version.id] = v.id
-    	end
-    	
-    	# Project categories
-    	project.categories.each do |category|
-          g = IssueCategory.new :name => category.category[0,30]
+        end
+ 
+        # Project categories
+        project.categories.each do |category|
+          g = IssueCategory.new :name => category.category
           g.project = p
           g.save
           categories_map[category.category] = g.id
-    	end
+    	  end
       end	
+      puts
+      
+      # Project Hierarchy
+      print "Making Project Hierarchy"
+      MantisProjectHierarchy.find(:all).each do |link|
+        next unless p = Project.find_by_id(projects_map[link.child_id])
+        p.set_parent!(projects_map[link.parent_id])
+        print '.'
+      end
       puts	
     
       # Bugs
@@ -310,22 +327,24 @@ task :migrate_from_mantis => :environment do
       keep_bug_ids = (Issue.count == 0)
       MantisBug.find_each(:batch_size => 200) do |bug|
         next unless projects_map[bug.project_id] && users_map[bug.reporter_id]
-    	i = Issue.new :project_id => projects_map[bug.project_id], 
+        i = Issue.new :project_id => projects_map[bug.project_id], 
                       :subject => encode(bug.summary),
                       :description => encode(bug.bug_text.full_description),
                       :priority => PRIORITY_MAPPING[bug.priority] || DEFAULT_PRIORITY,
-                      :created_on => bug.date_submitted,
-                      :updated_on => bug.last_updated
-    	i.author = User.find_by_id(users_map[bug.reporter_id])
-    	i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category[0,30]) unless bug.category.blank?
-    	i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
-    	i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
-    	i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
-    	i.id = bug.id if keep_bug_ids
-    	next unless i.save
-    	issues_map[bug.id] = i.id
-    	print '.'
-      STDOUT.flush
+                      :created_on => Time.at(bug.date_submitted)
+        i.author = User.find_by_id(users_map[bug.reporter_id])
+        i.category = IssueCategory.find_by_project_id_and_name(i.project_id, bug.category) unless bug.category.blank?
+        i.fixed_version = Version.find_by_project_id_and_name(i.project_id, bug.fixed_in_version) unless bug.fixed_in_version.blank?
+        i.status = STATUS_MAPPING[bug.status] || DEFAULT_STATUS
+        i.tracker = (bug.severity == 10 ? TRACKER_FEATURE : TRACKER_BUG)
+        i.start_date = Time.at(bug.date_submitted).to_date
+        i.due_date = (bug.due_date <= bug.date_submitted)? nil:Time.at(bug.due_date).to_date
+        i.updated_on = Time.at(bug.last_updated)
+        i.id = bug.id if keep_bug_ids
+        next unless i.save
+        issues_map[bug.id] = i.id
+        print '.'
+        STDOUT.flush
 
         # Assignee
         # Redmine checks that the assignee is a project member
@@ -333,17 +352,17 @@ task :migrate_from_mantis => :environment do
           i.assigned_to = User.find_by_id(users_map[bug.handler_id])
           i.save_with_validation(false)
         end        
-    	
-    	# Bug notes
-    	bug.bug_notes.each do |note|
-    	  next unless users_map[note.reporter_id]
+      
+        # Bug notes
+        bug.bug_notes.each do |note|
+          next unless users_map[note.reporter_id]
           n = Journal.new :notes => encode(note.bug_note_text.note),
-                          :created_on => note.date_submitted
+                          :created_on => Time.at(note.date_submitted)
           n.user = User.find_by_id(users_map[note.reporter_id])
           n.journalized = i
           n.save
-    	end
-    	
+        end
+      
         # Bug files
         bug.bug_files.each do |file|
           a = Attachment.new :created_on => file.date_added
@@ -376,7 +395,6 @@ task :migrate_from_mantis => :environment do
         STDOUT.flush
       end
       puts
-      
       # News
       print "Migrating news"
       News.destroy_all
@@ -385,7 +403,7 @@ task :migrate_from_mantis => :environment do
         n = News.new :project_id => projects_map[news.project_id],
                      :title => encode(news.headline[0..59]),
                      :description => encode(news.body),
-                     :created_on => news.date_posted
+                     :created_on => Time.at(news.date_posted)
         n.author = User.find_by_id(users_map[news.poster_id])
         n.save
         print '.'
@@ -508,5 +526,6 @@ task :migrate_from_mantis => :environment do
   
   MantisMigrate.establish_connection db_params
   MantisMigrate.migrate
+
 end
 end
