added null guard for onFinish