fix memory leak + small fixes