added unit tests thanks to @effi