Changed the order of some code