Exact modeling of generalised defect modes in photonic crystals