corrected bug causing memory leak