Refactor space validity checking.