refer and modify to teacher code