Reimplemented it and added tests.