So, when I view a category, if I click the sub-category links in the left side menu, the cpath is correct. But if I click on the category image in the middle of the page, the cpath is incorrect.

Example:
Link to subcategory from the left sidebox: cPath=57_25 CORRECT
Link to subcategory from the middle images: cPath=25 INCORRECT

This gives rise to problems like breadcrumbs being inaccurate, subcategories not showing on left side while in subcategory, etc etc.

If I knew which file controls these links, I can fix it. But cant for the life of me find the file! where is it located?