Fixed #607, fixed #608 and fixed #609