Fixed doctest. Added tests, documentation and doctest