fixed compilation error and potentil memory corruption