Fixed #559
and #589