Fix for regression in #331 and bug #344