initialize tmp to NULL