Fix for #87, #168, #172 and #183