Updated to return correct value from close handler