Restructure function ordering