changed space_detect function to support cross