Added memory cleanup and full code coverage.