added slightly smarter determine_service