Should fix issue #314 and other related problems

Please test again.