Move logic from Rake task into module