I think this method could be refactored into smaller methods