Fix issue #168 and #163

Fix issue #168 and #163