seems like this would have been vastly easier as a management command