optimize code in teacher app.