Small refactoring; fixing memory leak; adding copyright notice