Optimize thread and cpu usage

quick fixes throughout