Remove hardcoded chunk size and implement rewrite rules