add more logic to the chunking, better api and math