Fixed memory leak in retrieving data