Changed the order of definitions so that they work at the top level.