Fixed major memory leak, test improved