Fix invalid location logic