better way to detect leave/finish