Fix issues #493 and #502

I would like to resolve #493 and #502. Thanks.