call function from the right place