Make boundary restriction work, add unit test