Optimization for registration