added range checks for rectangles