fixed codgen bugs for multiloops with empty chunks; added test case; fixed threads setting in unit tests