Fix #679

Please read these changes carefully.