Refactored to similar Rails 3.2 version.