An extension theorem from connected sets, and homogenization in general periodic domains