fix and improve country detection