fix bug and improve function call.