issue #641 and other small fix