fixed database on rakefile and added date sort
fixed logic errors in the sort