In case of an exception a lot of stuff is not closed correctly here. Granted, the original code also failed to do this correctly but if you touch the code, be a deary and fix it, too. :)