Refactoring of sanity_checks() into several smaller functions to save my sanity (plus add PREFIX and URLFIX stuff)