Re-arranged functions to make code more linear.