Main function.