fix danging pointer exception