Incorporated some of the improvements suggested by jreback to chunk/util