fix some "implicite declaration" and "differ in signedness" warnings. Improve 64bit compatibility.