Added code to free allocated memory