adjusted main function