Fixed memory leak and bad index issues.
Merge pull request #7 from hjones2199/testing

Fixed memory leak and bad index issues.