Fixed #642, fixed #716, fixed #717