Fixed #551
Fixed #566
Fixed #540