fix weird order of functions bug