fix issues #39 and #40