Fixed #798 and #803