refactored boundary.c and other minor changes