empty finally block removed
key interation changed to entries iteration
unneccessary null checks removed
closing up all the streams