Moved various function calls to the appropriate action hooks