Fixed memcheck and small bug