Extended main with some functions.