Main function