fixes #9 and #8, need proper tests for #9