Extended explaination of main function.