Boundary function optimization working.