Rearranged code to avoid memory leak.