bugfix and speedup.