add fixes from https://bitsharestalk.org/index.php?topic=2510.msg40492#msg40492