added a working 'within' function