merged code from https://github.com/rravuri/tidl/pull/2