commit after cleaning code & initial threading

half code re- factored  and documented