working main function