implement main function