Re-organized the order of functions