Implements the main function