fixes potential memory leak problem