Fix issues #342 and #267.