Converted to use misc IOUtils instead of duplicating code