Code Optimization and Bug Fixes