second version
are there any more edge cases lurking?