fixed compilation errors on CLang and corrected all the warnings