fix bug #179 and #224