Added function to exclude points outside valid regions