correctly call function in callback