fixed memory problem, replaced switch