updated handler routine to fix race condition on nil handler