Fix for Issue #12

- fixed errors reported by valgrind