Add unit tests & improve some code
Add gracefull stop