move ui stuff to ui module
add some threading
fix device closing flow