Another attempt to fix #41 (missed half of the last fix, and now omitting it as it looks complicated).