Added IR Safeguard

- Also fixed bugs
- Also added const to constant declarations.