Fixed #517
Fixed #522