fix a print statement
replace global vars by dynamic memory allocation