bug fix for #3 and #5