rake task code optimized