Attempt to fix bugs #17 and #40