Fix issue #676

Fix #676 and #668