Got help from fernando, fixed memory problem