Optimization and security fixes