almost done, need to fix memory leak and normaly exit when receiving signal