Implementation of main function