Move callback initialization to prevent race condition