Fix issues #335 and #336

Here are my fixes for issues #335 and #336.

Details in the two commits.