Fix issue #46 and Fix issue #47