Code Optimization and RTL bugfix