fix #7 and improve a thread handling.