fixed some problems caused by model compression

the bug fixes also speed up the code