fixed coverity CID 1013823, added unit tests

title says it all :-)