reformat and add threading

refactor code to fit new standards
add threading to connect so it doesnt suck