addresses memory leak and fixes #10
fixes memort leak and merges with master