fixed memory bug with weak refs