Some fixes and refactor

Using Threads