Code Clean Up and Optimization