For #328 - various fixes