fixes #42, fixes #43, adds more tests