Refactor to use methods as the original rake task was getting a bit long.