fixed bug #40 and #39