reformed main function