Rewriting rake task to be more robust