Fixes for issues #328 and #582

Fixes for issues #328 and #582