Fixing resource leak by closing all stream manually in finally block.