Fixing resource leak