General functions for main