fix incorrect 2D boundary creation + refactoring
boundary were incorrect in 2D, this fixes this. While on it I modified the code a bit to reduce code duplication
boundary were incorrect in 2D, this fixes this. While on it I modified the code a bit to reduce code duplication