Close resources before return