Final version.
TODO: TESTS!