Fix issue #5 again. And some other improvements