Improve drawing speed of threshold code