Refactor boundary tests and code