fixed slowdown code