Close resources and clean up warnings