Simplify and improve thread api