Fixes for issue #337 and #336 

Fixes issue #337 and issue #336