This fixes #130 and #166 plus some minor issues