Fixed bug #706 and #679