Corrected conditionals and added protection for simultaneous master and replica configuration