Try to fix #321 and fix #287

Desperate times.