Cleanup. Added onClose handling