Added some protectons and corrected a bug making the install fail from time to time