Mitigating Pilot Contamination through Optimizing Pilot Allocation in Massive MIMO Systems