Fix some bug when generate code for function