Two changes that try to make the code easier to read and maintain in the future. The logic itself doesn't change. - Do not repeat the MediaProfile assignments. This makes the flow much easier to understand. And less error prone. - Do not mix error handling with actual logic. By throwing early, the actual selection logic that follows is more obvious.