I have refactored this into a separate file and extended the logic to handle the case when there are multiple interface adapters as pointed out by @teg.