Done some clean up.There might still be bugs with network..