Fix within function and add specs for it
Fix nearby function and add specs for it