fix and speedup