Fixed #802, fixed #803 and fixed #804