Fixed the boundary restrictions mentioned in previous commit
Not sure why this works, but it does.