Thread issues fixed, need a lot of optimization but it works.