Backport #169 and #171 from develop