Some general debuging and imporvments