Memory leak fixed.
Tests updated.