Fix #138 and #116.