address one memory leak and one logic error