fix allocated blocks calculation, and add more sanity checks