Fix issues #161 and #162
Merge pull request #443 from lilyfan/issue161

Fix issues #161 and #162