fixed coverity CID 1013823, added unit tests