Fix clear route logic and withinImage() function