Closes resources on lose