optimize controller codes