Identified mem leak - Requires fix.
Fixed memory leak and added tests.