Fixed #821 and fixed #822