Finally getting rid of this ugly global function...