fix stack smashing bug