updated based on jsbin.com/uqsig/2/edi