What is the mess inside the upper?
Step 1, clean it. Other than where anodizing has worn, should be original finish on the inside. check for burrs and gouging.
Step 2, What you are describing is most always gas related. Ensure barrel has gas port, gas block is not blocked, gas tube is not...