Added chunking function but not complete. fixes #581