fixed issues #584, #588 and #586