some minor bugfixes found along the way
test cases