generalize space function