Fix #124, #81 and #106
Signed-off-by: Peter Cai <xqsx43cxy@126.com>