fixes #8 and adds tests