Adding close methods and do code cleaning