Fix for #166 and #119