Fixed some major threading and performance issues