Fix warning and add 'finally' clause